<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * magento 网站相关功能
 */
class Magento extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('Function_m', 'fun');
        $this->load->model('Magento_m', 'mag');
		$this->pageSize =$this->config->item('pagenum');
    }

    //网站赞助赞助
    public function sponsor()
    {
        $this->sponsorindexdisplaytpl('*', '*', '*', '*', '*', '*', '*', 1);
    }


    public function sponsorindexdisplaytpl($where, $value, $mstype, $purpose, $starttime, $endtime, $ms_status, $page)
    {
        //构建sql语句
        $sql = $this->mag->sponsorindexdisplaytpl($where, $value, $mstype, $purpose, $starttime, $endtime, $ms_status);
        //把sql语句放入函数查询出所需数据
        $sponsorlist = $this->mag->getindextpl($sql, $page);
        //总计数量
        $sum = $this->mag->sqlcount($sql);
        //一直总数除以单页显示数量，然后分页显示
        $pages = ceil($sum / 30);
        //页码地址
        $pageurl = "/magento/ajaxbutton?op=sponsorsearch&where=$where&value=$value&mstype=$mstype&purpose=$purpose&starttime=$starttime&endtime=$endtime&ms_status=$ms_status";
        $this->tpl->assign('pageurl', $pageurl);
        $this->tpl->assign('pages', $pages);
        $this->tpl->assign('zero', 0);
        $lastpage = $page - 1;
        $this->tpl->assign('lastpage', $pages);
        $nextpage = $page + 1;
        $this->tpl->assign('nextpage', $pages);
        $pg = array();
        $from = ($page - 3 > 0 ? ($page - 3) : 1);
        $end = ($page + 3 < $pages ? ($page + 3) : $pages);
        for ($i = $from; $i <= $end; $i++) {
            $pg[] = $i;
        }
        $this->tpl->assign("pg", $pg);
        $this->tpl->assign("sum", $sum);
        for ($i = 0; $i < count($sponsorlist); $i++) {
            $sponsorlist[$i]['ms_img_data'] = json_decode($sponsorlist[$i]['ms_img_data'], true);
        }
        $this->tpl->assign("sponsorlist", $sponsorlist);
        if ($value == '*') $value = '';
        if ($starttime == '*') $starttime = '';
        if ($endtime == '*') $endtime = '';
        $this->tpl->assign("ms_status", $ms_status);
        $this->tpl->assign("value", $value);
        $this->tpl->assign("where", $where);
        $this->tpl->assign("mstype", $mstype);
        $this->tpl->assign("purpose", $purpose);
        $this->tpl->assign("starttime", $starttime);
        $this->tpl->assign("endtime", $endtime);
        $this->tpl->assign('rand', mt_rand(0, 1000));
        $this->tpl->display("magento/sponsor.tpl");

    }

	public function addnewproduct()
	{
		$shopname = $this->db->get_where("d_shop"," (platfrom = 14  ) AND del_flag = 0 and id !=72 ")->result_array();
		$newshop = "";
		foreach($shopname as $key=>$rs)
		{
			$newshop[$rs["platfromname"]][] = $rs;
		}

		
		$this->tpl->assign("shopname", $newshop);
		$this->tpl->display("magento/storere.tpl");
	}
	public function saveproductNext()
	{
		$goods_name = $this->input->post('goods_name');
		$sku = $this->input->post('sku');
		$category = $this->input->post('categorydata');//分类
		$categoryID = $this->input->post('categorydataID');//分类ID
		$price = $this->input->post('price');//价格
		$special_price = $this->input->post('special_price');//折扣价
		$weight = $this->input->post('weight');
		$including = $this->input->post('includingdata');
		$includingid = $this->input->post('includingdataid');
		$fabric = $this->input->post('fabricdata');
		$fabricid = $this->input->post('fabricdataid');
		$short_description = $this->input->post('short_description');
		$meta_title = $this->input->post('meta_title');
		$meta_keywords = $this->input->post('meta_keywords');
		$description = $this->input->post('description');
		$webname = $this->input->post('webname');
		$attributeID = $this->input->post('attributedataID');
		$shopid = $this->input->post('shopid');
		$related = $this->input->post('related');
		$up_sell = $this->input->post('up_sell');
		
		$goodsid = $this->input->post('goodsid');

		if($goods_name)
		{
			$insertID="";
			foreach($goods_name as $key=>$rs)
			{
				$post="";
				$post["product_id"] = 0;
				$post["parent_id"] = 0;
				$post["webname"] = $webname[$key];
				$post["shopid"] = $shopid[$key];
				$post["is_open"] = 0;
				$post["sku"] = trim($sku);
				$post["name"] = $rs;
				$post["description"] = $description[$key];
				$post["short_description"] = $short_description[$key];
				$post["weight"] = $weight[$key];
				$post["categoryID"] = $categoryID[$key];
				$post["price"] = $price[$key];
				$post["special_price"] = $special_price[$key];
				$post["meta_title"] = $meta_title[$key];
				$post["meta_keywords"] = $meta_keywords[$key];
				$post["including"] = $including[$key];
				$post["fabric"] = $fabric[$key];
				$post["isupload"] = 0;
				$post["includingid"] = $includingid[$key];
				$post["fabricid"] = $fabricid[$key];
				$post["attributeid"] = $attributeID[$key];
                $post['related'] = $related[$key];
                $post['up_sell'] = $up_sell[$key];
				if($goodsid){
					$this->db->update("db_magento_productlist",$post,"id='".$goodsid."'");
					$insertID[] = $goodsid;
				}else{
					$this->db->insert("db_magento_productlist",$post);
					$insertID[] = $this->db->insert_id();
				}
			}
		}
		if(count($insertID))
		{
			$insertID  = implode(",",$insertID);
			 header("location:/magento/ajaxbutton?op=addproductimages&id={$insertID}");
		}else{
			die('没有数据');
		}
	}
	public function productlist()
	{
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
        $where = " ";
		
		
		
		if($this->input->get_post('webname'))
		{
			$webname = $this->input->get_post('webname');
			 $where.=" AND webname ='".$webname."'";
			 $this->tpl->assign("webnamevalue", $this->input->get_post('webname'));
		}


		$starttime = trim($this->input->get('starttime'));
		if ($starttime) {
			$times = $starttime . " 00:00:00";
			$timess = strtotime($times);
			$where .= " AND (intime >= '" . $timess . "')";
			$this->tpl->assign("starttime", $starttime);
		}

		$endtime = trim($this->input->get('endtime'));
		if ($endtime) {
			$times = $endtime . " 23:59:59";
			$endtimes = strtotime($times);
			$where .= " AND (intime <= '" . $endtimes. "')";
			$this->tpl->assign("endtime", $endtime);
		}
		if ($this->input->get_post('kw')) {
			$kw = trim($this->input->get_post('kw'));
			$where .= " AND (sku like '%" . $kw. "%' or name like '%" . $kw. "%')";
			$this->tpl->assign("kw", $kw);
		}

		$list = $this->fun->getalllist("db_magento_productlist ", $where, $nowpage, $if_csv, $this->pageSize, $orderby);
		foreach($list["list"] as $key=>$rs)
		{
			 $list["list"][$key]['name'] = stripslashes($rs['name']);
			 $list["list"][$key]['waittime'] =date("Y-m-d H:i:s",$rs['intime']);
			
		}

		$webname = $this->fun->getdatabaseslist("db_magento_productlist","","DISTINCT webname ");
		$this->tpl->assign("webname", $webname);
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
        $this->tpl->assign("productlist", $list["list"]);

		
		$this->tpl->display("magento/productlist.tpl");
	}

	public function saveupload()
	{
		$url = $this->config->item('system_oray_url');
		$url = trim($url,"/");
		$imagetype = $this->input->post('imagetype');
		$id = $this->input->post('id');
		foreach($imagetype as $key=>$val)
		{
			$rsdb = $this->fun->getdatabasesdetail("db_magento_productlist"," AND id ='".$id[$key]."'");
			if($val==1)
			{
				//系统用图片保存在待处理阶段
				$images = $this->fun->getdatabasesdetail("goodimages.goods"," AND number = '".$rsdb['sku']."'");
				$imagesID = $images["id"];
				$imageslist = $this->fun->getdatabaseslist("goodimages.goodpics"," AND type = 5 and pid = '".$imagesID."'","picurl");
				$imagesdata = "";
				if(count($imageslist)){
					
					foreach($imageslist as $k=>$res)
					{
						$imagesdata[]= $url.":50/".$res["picurl"];
					}
				}
				if($imagesdata)
				{
					$imagesdata = implode("|",$imagesdata);
					$this->db->update("db_magento_productlist",array("uploadImages"=>$imagesdata,"images_type"=>1),"id='".$id[$key]."'");
				}
			}
		}
		//开始存储信息
		foreach($id as $key=>$val)
		{
			$rsdb = $this->fun->getdatabasesdetail("db_magento_productlist"," AND id ='".$val."'");
			$Newarray  = array();
			$Newarray["name"] =  $rsdb["name"];
			$Newarray["weight"] =  $rsdb["weight"];
			$Newarray["price"] =  $rsdb["price"];
			$Newarray["special_price"] =  $rsdb["special_price"];
			$Newarray["short_description"] =  $rsdb["short_description"];
			$Newarray["including"] =  $rsdb["includingid"];
			$Newarray["attributeid"] =  $rsdb["attributeid"];
			$Newarray["fabric"] =  $rsdb["fabricid"];
			$Newarray["description"] =  $rsdb["description"];
			$Newarray["categoryID"] =  $rsdb["categoryID"];
			$Newarray["is_open"] =  0;
			$Newarray['related'] = $rsdb['related'];
			$Newarray['up_sell'] = $rsdb['up_sell'];
			$update =  json_encode($Newarray);
			$post="";
			$post["isupload"] = 1;
			$post["updateData"] = $update;
			$this->db->update('db_magento_productlist',$post,"id=".$rsdb['id']);
		}

		 header("location:/magento/productlist");
		 die;
		//开始直接更新数据
		$this->load->library('Magentodata');
		$this->magentodata->updatemagentwebdata();
		 header("location:/magento/productlist");
		 die;
	}
	

    public function ajaxbutton()
    {
        $op = $this->input->get_post('op');
        if ($op == 'creatsponsor') {
            $type = trim($this->input->get('type'));
            if ($type == 0) {
                $this->tpl->assign("type", $type);
                $this->tpl->assign("sponsorlist", '');
            }
            if ($type == 1) {
                $this->tpl->assign("type", $type);
                $id = $this->input->get('id');
                $data = $this->mag->sponsorlist($id);
                $sponsorimg = json_decode($data[0]['ms_img_data'], true);
                $this->tpl->assign("sponsorimg", $sponsorimg);
                $this->tpl->assign("sponsorlist", $data);
            }
            $this->tpl->assign("nowuserid", $_COOKIE["userid"]);
            $this->tpl->display("magento/creatsponsorlist.tpl");

        }
		if($op =='updatemagentwebdata')
		{
			$this->load->library('Magentodata');
			$this->magentodata->updatemagentwebdata();
			echo "等待更新中！";
			die;
		}
		if($op =='getRemotedata')
		{
			$this->load->library('Magentodata');
			$this->magentodata->getRemotedata();
		}
        if ($op == 'savesponsor') {
            $type = $this->input->post('type');
            $into['ms_type'] = $this->input->post('ms_type');
            $into['ms_purpose'] = $this->input->post('ms_purpose');
            $into['ms_blog_url'] = $this->input->post('ms_blog_url');
            $into['ms_website_pr'] = $this->input->post('ms_website_pr');
            $into['ms_social_media_url'] = $this->input->post('ms_social_media_url');
            $into['ms_funs_number'] = $this->input->post('ms_funs_number');
            $into['ms_activity_address'] = $this->input->post('ms_activity_address');
            $into['ms_product_info'] = $this->input->post('ms_product_info');
            $into['ms_object_address'] = $this->input->post('ms_object_address');
            $into['ms_object_city'] = $this->input->post('ms_object_city');
            $into['ms_object_state'] = $this->input->post('ms_object_state');
            $into['ms_object_country'] = $this->input->post('ms_object_country');
            $into['ms_object_post_code'] = $this->input->post('ms_object_post_code');
            $into['ms_object_tp'] = $this->input->post('ms_object_tp');
            $into['ms_object_remarks'] = trim($this->input->post('ms_object_remarks'));
            $into['ms_object_name'] = $this->input->post('ms_object_name');
            $into['ms_object_email'] = $this->input->post('ms_object_email');
            $into['ms_object_money'] = $this->input->post('ms_object_money');
            $into['ms_object_money_sign'] = $this->input->post('ms_object_money_sign');
            $into['ms_object_startime'] = $this->input->post('ms_object_startime');
            $into['ms_object_endtime'] = $this->input->post('ms_object_endtime');
            $into['ms_remarks'] = trim($this->input->post('ms_remarks'));
            $into['ms_source'] = trim($this->input->post('ms_source'));
            $into['ms_number_transactions'] = trim($this->input->post('ms_number_transactions'));
            $into['ms_income'] = trim($this->input->post('ms_income'));
            $into['ms_rmb_income'] = trim($this->input->post('ms_rmb_income'));
            $intojson = json_encode($into);
            if ($type == 0) {
                $this->mag->savesponsor($intojson);
            }
            if ($type == 1) {
                $id = $this->input->post('id');
                $this->mag->sponsorupdata($intojson, $id);
            }
            echo "/magento/sponsor?rand=" . mt_rand(0, 1000);

        }


        if ($op == 'examination') {
            $id = trim($this->input->post('id'));
            $type = trim($this->input->post('type'));
            $this->mag->examination($id, $type);
            echo "/magento/sponsor?rand=" . mt_rand(0, 1000);
        }

        if ($op == 'sponsorsearch') {
            $where = trim($this->input->get('where'));
            $value = trim($this->input->get('value'));
            $value = (empty($value) ? '*' : $value);
            $mstype = trim($this->input->get('mstype'));
            $page = trim($this->input->get('page'));
            $page = (empty($page) ? '1' : $page);
            $purpose = trim($this->input->get('purpose'));
            $starttime = trim($this->input->get('starttime'));
            $endtime = trim($this->input->get('endtime'));
            $ms_status = trim($this->input->get('ms_status'));
            if (empty($starttime)) $starttime = '*';
            if (empty($endtime)) $endtime = '*';

            $this->sponsorindexdisplaytpl($where, $value, $mstype, $purpose, $starttime, $endtime, $ms_status, $page);

        }

        if ($op == 'sponsordelect') {
            $id = $this->input->post('id');
            $this->mag->sponsordelect($id);
            echo "/magento/sponsor?rand=" . mt_rand(0, 1000);
        }

		/**********获取所有店铺的基本产品信息*************/
		if($op =='getallproduct')
		{
		set_time_limit(0);
		/*
		$url = "http://cosplaysky.de/getallproduct/product_json.php";
		$post_data = "";
		$code=hash_hmac('sha256','2018','magento1');
		$code=base64_encode($code);
		$post_data=array('Authorization'=>$code);
		$header = array('Content-Type: application/json', "Authorization:" . $code);
		$datalist = $this->fun->curlfunc($url,json_encode($post_data),$cookie_jar="",$header);

			if($datalist)
			{
				$datalist = json_decode($datalist,true);
				$post = "";

				foreach($datalist as $key=>$rs)
				{
					$chrow = $this->fun->getdatabasesdetail("`db_magento_productlist`"," and webname = '".$rs["webname"]."' AND `product_id` = '".$rs['product_id']."'  ");
					if(!$chrow){
						$post[$key]['product_id']=$rs['product_id'];
						$post[$key]['product_url'] = $rs['product_url'];
						$post[$key]['webname'] = $rs["webname"];
						$post[$key]['name'] = addslashes($rs["name"]);
						$post[$key]['is_open'] = 0;
						$post[$key]['sku'] = $rs["sku"];
						$post[$key]['description'] =addslashes($rs["description"]);
						$post[$key]['short_description'] = addslashes($rs["short_description"]);
						$post[$key]['weight'] = $rs["weight"];
						$post[$key]['price'] = $rs["price"];
						$post[$key]['currency'] = $rs["currency"];
						$post[$key]['special_price'] = $rs["special_price"];
						$post[$key]['meta_title'] = $rs["meta_title"];
						$post[$key]['meta_keywords'] = $rs["meta_keywords"];
						$post[$key]['base_image'] = $rs["base_image"];
						$post[$key]['small_image'] = $rs["small_image"];
						$post[$key]['thumbnail_image'] = $rs["thumbnail_image"];
						$post[$key]['including'] = trim($rs["including"],",");
						$post[$key]['fabric'] = trim($rs["fabric"],",");
						$post[$key]['images'] = $rs["img"];
					}
				}
				if(count($post)){
					$this->db->insert_batch('db_magento_productlist',$post);
				}
				echo "OK";
			}
			*/
			$this->load->library('Magentodata');
			$this->magentodata->getwebproduct();
			echo "OK";
			die;
		}

		/**********获取所有店铺的分类*************/
		if($op =='getcategorytree')
		{
		
			
		$this->db2 = $this->load->database('amazondata', TRUE);
		$row = $this->db2->get("db_magento_data")->result_array();
		if($row)
		{
			foreach($row as $key=>$rs)
			{
				$rres = $this->fun->getdatabasesdetail("db_magento_cateory"," and shopid =  ".intval($rs['shopid']));
				if($rres)
				{
					$post = "";
					$post["including_fabric"] = $rs['including_fabric'];
					$post["categorytree"] = $rs['categorytree'];
					$post["productdata"] = $rs['productdata'];
					$this->db->update("db_magento_cateory",$post," shopid = '".$rs["shopid"]."'");
				}else{
					$post = "";
					$post["shopid"] = $rs['shopid'];
					$post["including_fabric"] = $rs['including_fabric'];
					$post["categorytree"] = $rs['categorytree'];
					$post["productdata"] = $rs['productdata'];
					$this->db->insert("db_magento_cateory",$post);
				
				}
			}
		}





		
			die("关闭本页面！再刷新原页面即出现分类！");
		}
		//上传图片
        if ($op == 'upimages') {
            $msg = $this->mag->savedoupload();
            //var_dump($msg);
            if ($msg["st"] != 200) {
                var_dump($msg);
            } else {
                header("location:{$msg['url']}");
            }

        }

        //删除上传的图片
        if ($op == 'deleteimg') {
            $id = trim($this->input->post('id'));
            $key = trim($this->input->post('key'));
            $this->mag->deleteimg($id, $key);
            echo "/magento/ajaxbutton?op=creatsponsor&type=1&id={$id}&rand=" . rand(0, 1000);
        }

        //上传赞助统计csv
        if ($op == 'upincomecsv') {
            $ms_income_currency = trim($this->input->post('ms_income_currency'));
            $timedata = trim($this->input->post('timedata'));
            $filename = $_FILES['userfile']['tmp_name'];
            $handle = fopen($filename, 'r');
            $upload = array();
            while ($data = fgetcsv($handle)) {
                unset($info);
                $info = array();
                foreach ($data as $v) {
                    $info[] = htmlentities($v);
                }
                $upload[] = $info;
            }
            //$this->mag->uploadcsv($upload,$ms_income_currency);
            //把数据显示出来，然后确认无误后再行导入
            //自动把无效数据跳过，
            $data = array();//最终数据
            foreach ($upload as $value) {
                if ($value[0] == '' || $value[0] == null)
                    continue;
                else
                    $data[] = $value;
            }
            $this->tpl->assign("data", $data);
            $this->tpl->assign("jsondata", json_encode($data));
            $this->tpl->assign("ms_income_currency", $ms_income_currency);
            $this->tpl->assign("timedata", $timedata);
            $this->tpl->display("magento/confirmupincome.tpl");

        }

		//确认上传数据
        if ($op == 'confirmcsv') {
            $ms_income_currency = trim($this->input->post('ms_income_currency'));
            $timedata = trim($this->input->post('timedata'));
            $jsondata = trim($this->input->post('jsondata'));
            $data = json_decode($jsondata, true);
            $this->mag->uploadcsv($data, $ms_income_currency, $timedata);
            echo "/magento/sponsor?rand=" . mt_rand(0, 1000);
        }

		//转化数据统计/usr/local/mysql/bin/mysqld_safe &
        if ($op == 'successdata') {
            $type = trim($this->input->get('type'));
            //获取db_magento_sponsor_income 时间段，
            $timedatalist = $this->mag->get_db_magento_sponsor_income();
            $this->tpl->assign("timedatalist", $timedatalist);
            if ($type == 0)
                $this->tpl->display("magento/successdata.tpl");
            else {
                $ms_user = trim($this->input->get('ms_user'));
                $ms_object_name = trim($this->input->get('ms_object_name'));
                $ms_source = trim($this->input->get('ms_source'));
                $timedata = trim($this->input->get('timedata'));
                $data = $this->mag->successdata($ms_user, $ms_object_name, $ms_source, $timedata);
                $this->tpl->assign("ms_user", $ms_user);
                $this->tpl->assign("ms_object_name", $ms_object_name);
                $this->tpl->assign("ms_source", $ms_source);
                $this->tpl->assign("timedata", $timedata);
                $sum = 0;
                foreach ($data as $value) {
                    $sum += $value['ms_rmb_income'];
                }
                $this->tpl->assign("sum", $sum);
                $this->tpl->assign("data", $data);
                $this->tpl->display("magento/successdata.tpl");
            }
        }
		/**添加新品第二步*/
		if($op =='addproductnext')
		{
			if($this->input->post_get('shopID'))
			{
				$shopID = $this->input->post_get('shopID');
				$strshopID = implode($shopID,",");
				
				$shopname = $this->db->select('id,name,platfrom,platfromname,amazonkey')->get_where("d_shop"," id in($strshopID)")->result_array();
				$newshop = array();
				foreach($shopname as $key=>$rs)
				{
					$amazonkey = json_decode($rs["amazonkey"],true);
					if($amazonkey["magentourl"]=="")
					{
						echo "店铺".$rs["name"]." 没有设置授权信息和网址!请联系管理员设置！";
						die;
					}
					$newshop[$key]["id"] = $rs["id"];
					$newshop[$key]["name"] = $rs["name"];
					$newshop[$key]["platfrom"] = $rs["platfrom"];
					$newshop[$key]["platfromname"] = $rs["platfromname"];
					$newshop[$key]["webname"] = $amazonkey["magentourl"];

					$rsdb = $this->fun->getdatabasesdetail("db_magento_cateory"," and shopid =  {$rs[id]}");//分类
					$including_fabric = unserialize($rsdb["including_fabric"]);
					$including = $including_fabric['including'];
					$fabric = $including_fabric['fabric'];
					$categorytree = unserialize($rsdb["categorytree"]);
					if($rsdb["productdata"])$productdata = unserialize($rsdb["productdata"]);
				
					$newshop[$key]["categorytree"] = $categorytree;
					$newshop[$key]["including"] = $including;
					$newshop[$key]["fabric"] = $fabric;
					$newshop[$key]["productdata"] = $productdata;
					//查询货币
				}

				$this->tpl->assign("newshop", $newshop);
				$this->tpl->display("magento/addproductnext.tpl");
			}
			


		}

		/**修改第二步*/
		if($op =='Editproductnext')
		{
			if($this->input->post_get('id'))
			{
				$id = $this->input->post_get('id');
				$goods = $this->fun->getdatabasesdetail("db_magento_productlist"," and id = '".$id."'");
				$shopname = $this->db->select('id,name,platfrom,platfromname,amazonkey')->get_where("d_shop","  id = '".$goods["shopid"]."'")->result_array();
				$newshop = array();
				foreach($shopname as $key=>$rs)
				{
					$amazonkey = json_decode($rs["amazonkey"],true);
					if($amazonkey["magentourl"]=="")
					{
						echo "店铺".$rs["name"]." 没有设置授权信息和网址!请联系管理员设置！";
						die;
					}
					$newshop[$key]["id"] = $rs["id"];
					$newshop[$key]["name"] = $rs["name"];
					$newshop[$key]["platfrom"] = $rs["platfrom"];
					$newshop[$key]["platfromname"] = $rs["platfromname"];
					$newshop[$key]["webname"] = $amazonkey["magentourl"];
					

					$rsdb = $this->fun->getdatabasesdetail("db_magento_cateory"," and shopid =  {$rs[id]}");//分类
					$including_fabric = unserialize($rsdb["including_fabric"]);
					$including = $including_fabric['including'];
					$fabric = $including_fabric['fabric'];
					$categorytree = unserialize($rsdb["categorytree"]);
					if($rsdb["productdata"])$productdata = unserialize($rsdb["productdata"]);
				
					$newshop[$key]["categorytree"] = $categorytree;
					$newshop[$key]["including"] = $including;
					$newshop[$key]["fabric"] = $fabric;
					$newshop[$key]["productdata"] = $productdata;
					//查询货币
				}
				$this->tpl->assign("newshop", $newshop);
				$this->tpl->assign("goods", $goods);
				$this->tpl->display("magento/Editproductnext.tpl");
			}
		}
			//上传图片
		if($op =='addproductimages')
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$id = $this->input->get('id');
			$list = $this->db->get_where('db_magento_productlist'," id in($id)")->result_array();
			foreach($list as $key=>$rs)
			{
				$sku = $rs["sku"];
				
				$images = $this->fun->getdatabasesdetail("goodimages.goods"," AND number = '".$sku."'");
				$imagesID = $images["id"];
				$imageslist = $this->fun->getdatabaseslist("goodimages.goodpics"," AND type = 5 and pid = '".$imagesID."'","name,picurl");
				if(count($imageslist)){
					foreach($imageslist as $k=>$res)
					{
						$imageslist[$k]["picurl"] = $url.":50/".$res["picurl"];
					}
					$list[$key]["imagelist"] = $imageslist;
				}else{
					$list[$key]["imagelist"] = 0;
				}

				//本地
				if($rs["uploadImages"])
				{
					$nimageslist = explode("|",$rs["uploadImages"]);
					$newimages="";
					foreach($nimageslist as $keys=>$rss)
					{
						$newimages[] =str_replace($url.":66","",$rss);
					}
					$list[$key]["uploadImages"] = $newimages;
				}
			}

			$this->tpl->assign("list", $list);
			$this->tpl->assign("urlID", $id);
			$this->tpl->display("magento/addproductimages.tpl");
		}
		if($op =="saveProductImages")
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$ID = $this->input->post('MergeProductID');
			$insertID = $this->input->post('urlID');
			$filepath = $this->input->post('filepath');
			if(count($filepath))
			{
				foreach($filepath as $k=>$res)
				{
					$imageslist[]= $url.":66".$res;
				}
				$newimages = implode("|",$imageslist);
				$this->db->update("db_magento_productlist",array("uploadImages"=>$newimages,"images_type"=>2),"id='".$ID."'");
			}
			$this->fun->phpalert(1, "上传完成", "/magento/ajaxbutton?op=addproductimages&id={$insertID}");
			die;
		}

		if($op =="showImages")
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$id = $this->input->post('id');
			$list = $this->fun->getdatabasesdetail("db_magento_productlist"," AND id='".$id."'");
			$imageslist = $list["uploadImages"];
			if($imageslist)
			{
				$imageslist = explode("|",$imageslist);
				foreach($imageslist as $key=>$rs)
				{
					$newimages[] =str_replace($url.":66","",$rs);
				}
				echo json_encode($newimages);
				die;
			}

			
		
		}
		if($op =='getwebsku')
		{
			$res = $this->fun->getdatabasesdetail("db_magento_productlist"," AND webname='".trim($this->input->post('webname'))."' AND sku='".trim($this->input->post('sku'))."' ");
			if($res)
			{
				echo 200;
				die;
			}
		}
		if($op =='saveupdate')
		{
			$sku = $this->input->post('sku');
			$id = $this->input->post('id');
			$name = $this->input->post('name');
			$weight = $this->input->post('weight');
			$price = $this->input->post('price');
			$special_price = $this->input->post('special_price');
			$short_description = $this->input->post('short_description');
			$meta_title = $this->input->post('meta_title');
			$meta_keywords = $this->input->post('meta_keywords');

			$including = $this->input->post('including');
			$fabric = $this->input->post('fabric');
			$is_open = $this->input->post('is_open');
			$description = $this->input->post('description');

			$related = $this->input->post('related');
			$up_sell = $this->input->post('up_sell');
			
			if($id)
			{
				foreach($id  as $key=>$v)
				{
					$Newarray  = array();
					$rsdb = $this->fun->getdatabasesdetail('db_magento_productlist'," AND id ='".intval($v)."'","*");
					if($name[$key] != stripslashes($rsdb["name"]) )
					{
						$Newarray["name"] =  $name[$key];
					}
					if($weight[$key] != $rsdb["weight"])
					{
						$Newarray["weight"] =  $weight[$key];
					}
					if($price[$key] != $rsdb["price"])
					{
						$Newarray["price"] =  $price[$key];
					}
					if($special_price[$key] != $rsdb["special_price"])
					{
						$Newarray["special_price"] =  $special_price[$key];
					}
					if($short_description[$key] !=stripslashes($rsdb["short_description"]))
					{
						$Newarray["short_description"] =  $short_description[$key];
					}
					if($meta_title[$key] !=stripslashes($rsdb["meta_title"]))
					{
						$Newarray["meta_title"] =  $meta_title[$key];
					}
					if($meta_keywords[$key] !=stripslashes($rsdb["meta_keywords"]))
					{
						$Newarray["meta_keywords"] =  $meta_keywords[$key];
					}
					if($including[$key] !=stripslashes($rsdb["including"]))
					{
						$Newarray["including"] =  $including[$key];
					}
					if($fabric[$key] !=stripslashes($rsdb["fabric"]))
					{
						$Newarray["fabric"] =  $fabric[$key];
					}
					if($description[$key] !=stripslashes($rsdb["description"]))
					{
						$Newarray["description"] =  $description[$key];
					}

					if($is_open[$key] !=$rsdb["is_open"])
					{
						$Newarray["is_open"] =  $is_open[$key];
					}

					if($related[$key] != stripslashes($rsdb['related']))
					{
						$Newarray['related'] = $related[$key];
					}

					if($up_sell[$key] != stripslashes($rsdb['up_sell']))
					{
						$Newarray['up_sell'] = $up_sell[$key];
					}
					
					if($Newarray){
						$this->db->update('db_magento_productlist',$Newarray,"id=".$rsdb['id']);
						$update =  json_encode($Newarray);
						$post="";
						$post["isupload"] = 1;
						$post["updateData"] = $update;
						$this->db->update('db_magento_productlist',$post,"id=".$rsdb['id']);
						
					}
					
				

				}

				
			}
			
			/****开始执行程序更新到远程服务器*******/
			$this->load->library('Magentodata');
			$this->magentodata->updatemagentwebdata();
			$this->fun->phpalert(4, "", '', "/magento/productlist");

		}
		if($op =='getimages')
		{
			$rsdb = $this->fun->getdatabasesdetail('db_magento_productlist'," AND id ='".intval($this->input->post('id'))."'","small_image");
			echo json_encode($rsdb);
			die; 
		}
		if($op =='getonegoods')
		{
			$id = $this->input->post('id');
			$id =trim($id,",");
			$rsdb = $this->fun->getdatabaseslist('db_magento_productlist'," AND id in ($id)","webname,is_open,sku,name,description,short_description,weight,currency,price,special_price,meta_title,meta_keywords,including,fabric,id,updateData");
			
			if($rsdb)
			{
				$html="";
				foreach($rsdb as $key=>$data)
				{
					$description = stripslashes($data['description']);

					$data['name'] = stripslashes($data['name']);
					$data['meta_title']= stripslashes($data['meta_title']);
					$data['meta_keywords']= stripslashes($data['meta_keywords']);
					$data['fabric']= stripslashes($data['fabric']);
					$data['including']= stripslashes($data['including']);
					$data['short_description']= stripslashes($data['short_description']);

					if($data["is_open"]==1) $che1="selected";
					if($data["is_open"]==2) $che2="selected";
					if($data["is_open"]==0) $che0="selected";
					//属性
					//$including = "<td><textarea name=\"including[]\" cols=\"45\" rows=\"3\">".$data['including']."</textarea></td><td><textarea name=\"fabric[]\" cols=\"45\" rows=\"3\">".$data['fabric']."</textarea></td>";
					
					$html.="<tr>";
					$html.="<td>{$data['webname']}<input name=\"id[]\" value=\"".$data['id']."\" type=\"hidden\" /></td><td><input name=\"sku[]\" id=orderid{$data['sku']} placeholder=\"商品编号\" readonly class=\"width100\" type=\"text\" value=".$data['sku']."></td><td><textarea name=\"name[]\" cols=\"45\" rows=\"3\">".$data['name']."</textarea></td><td><input name=\"weight[]\" class=\"width100\" id=\"weight\" type=\"text\"  value=".$data['weight']." style=\"width:30px;\"></td><td><input name=\"price[]\" id=\"price\"  value=".$data['price']." type=\"text\" style=\"width:50px;\">".$data['currency']."</td><td><input name=\"special_price[]\" id=\"special_price\"  value=".$data['special_price']." type=\"text\"  style=\"width:50px;\">".$data['currency']."</td><td><textarea name=\"short_description[]\" cols=\"45\" rows=\"3\">".$data['short_description']."</textarea></td><td><textarea name=\"meta_title[]\" cols=\"45\" rows=\"3\">".$data['meta_title']."</textarea></td><td><textarea name=\"meta_keywords[]\" cols=\"45\" rows=\"3\">".$data['meta_keywords']."</textarea></td><td><select name=\"is_open[]\" id=\"is_open\" class=\"selection\" ><option value=\"0\" {$che0}>正常销售</option> <option value=\"1\" {$che1}>商品停售</option> <option value=\"2\" {$che2}>库存设零</option> </select></td><td><textarea name=\"description[]\" cols=\"45\" rows=\"3\">".$description."</textarea></td>";
					$html.="</tr>";
				}
			}
			echo $html;
			die;
			//echo json_encode($rsdb);
		}
        //shopify 获取产品
		if($op =='shopifygetonegoods')
		{
			$id = $this->input->post('id');
			$id =trim($id,",");
			$rsdb = $this->fun->getdatabaseslist('shopify.db_shopify_productlist'," AND id in ($id)","webname,is_open,sku,name,description,short_description,weight,currency,price,special_price,meta_title,meta_keywords,including,fabric,id,updateData");
			
			if($rsdb)
			{
				$html="";
				foreach($rsdb as $key=>$data)
				{
					$description = stripslashes($data['description']);

					$data['name'] = stripslashes($data['name']);
					$data['meta_title']= stripslashes($data['meta_title']);
					$data['meta_keywords']= stripslashes($data['meta_keywords']);
					$data['fabric']= stripslashes($data['fabric']);
					$data['including']= stripslashes($data['including']);
					$data['short_description']= stripslashes($data['short_description']);

					if($data["is_open"]==1) $che1="selected";
					if($data["is_open"]==2) $che2="selected";
					if($data["is_open"]==0) $che0="selected";
					//属性
					//$including = "<td><textarea name=\"including[]\" cols=\"45\" rows=\"3\">".$data['including']."</textarea></td><td><textarea name=\"fabric[]\" cols=\"45\" rows=\"3\">".$data['fabric']."</textarea></td>";
					
					$html.="<tr>";
					$html.="<td>{$data['webname']}<input name=\"id[]\" value=\"".$data['id']."\" type=\"hidden\" /></td><td><input name=\"sku[]\" id=orderid{$data['sku']} placeholder=\"商品编号\" readonly class=\"width100\" type=\"text\" value=".$data['sku']."></td><td><textarea name=\"name[]\" cols=\"45\" rows=\"3\">".$data['name']."</textarea></td><td><input name=\"weight[]\" class=\"width100\" id=\"weight\" type=\"text\"  value=".$data['weight']." style=\"width:30px;\"></td><td><input name=\"price[]\" id=\"price\"  value=".$data['price']." type=\"text\" style=\"width:50px;\">".$data['currency']."</td><td><input name=\"special_price[]\" id=\"special_price\"  value=".$data['special_price']." type=\"text\"  style=\"width:50px;\">".$data['currency']."</td><td><select name=\"is_open[]\" id=\"is_open\" class=\"selection\" ><option value=\"0\" {$che0}>正常销售</option> <option value=\"1\" {$che1}>商品停售</option> <option value=\"2\" {$che2}>库存设零</option> </select></td><td><textarea name=\"description[]\" cols=\"45\" rows=\"3\">".$description."</textarea></td>";
					$html.="</tr>";
				}
			}
			echo $html;
			die;
			//echo json_encode($rsdb);
		}

				/**shopify添加新品第二步*/
		if($op =='shopifyaddproductnext')
		{
			if($this->input->post_get('shopID'))
			{
				$shopID = $this->input->post_get('shopID');
				$strshopID = implode($shopID,",");
				
				$shopname = $this->db->select('id,name,platfrom,platfromname,amazonkey')->get_where("d_shop"," id in($strshopID)")->result_array();
				$newshop = array();
				foreach($shopname as $key=>$rs)
				{
					$amazonkey = json_decode($rs["amazonkey"],true);
					// if($amazonkey["magentourl"]=="")
					// {
					// 	echo "店铺".$rs["name"]." 没有设置授权信息和网址!请联系管理员设置！";
					// 	die;
					// }
					$newshop[$key]["id"] = $rs["id"];
					$newshop[$key]["name"] = $rs["name"];
					$newshop[$key]["platfrom"] = $rs["platfrom"];
					$newshop[$key]["platfromname"] = $rs["platfromname"];
					$newshop[$key]["webname"] = $amazonkey["shopifytoken"];

					$rsdb = $this->db->get_where("shopify.db_shopify_cateory","shopid =  {$rs[id]}")->result_array();//分类
					$including_fabric = unserialize($rsdb[0]["including_fabric"]);
					$including = $including_fabric['including'];
					$fabric = $including_fabric['fabric'];
					$categorytree = unserialize($rsdb[0]["categorytree"]);
					if($rsdb[0]["productdata"])$productdata = unserialize($rsdb[0]["productdata"]);
					$newshop[$key]["categorytree"] = $categorytree;
					$newshop[$key]["including"] = $including;
					$newshop[$key]["fabric"] = $fabric;
					$newshop[$key]["productdata"] = $productdata;
					//查询货币
				}

				$this->tpl->assign("newshop", $newshop);
				$this->tpl->display("magento/shopifyaddproductnext.tpl");
			}
			


		}

				if($op =='shopifyaddproductimages')
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$id = $this->input->get('id');
			$list = $this->db->get_where('shopify.db_shopify_productlist'," id in($id)")->result_array();
			foreach($list as $key=>$rs)
			{
				$sku = $rs["sku"];
				
				$images = $this->fun->getdatabasesdetail("goodimages.goods"," AND number = '".$sku."'");
				$imagesID = $images["id"];
				$imageslist = $this->fun->getdatabaseslist("goodimages.goodpics"," AND type = 5 and pid = '".$imagesID."'","name,picurl");
				if(count($imageslist)){
					foreach($imageslist as $k=>$res)
					{
						$imageslist[$k]["picurl"] = $url.":50/".$res["picurl"];
					}
					$list[$key]["imagelist"] = $imageslist;
				}else{
					$list[$key]["imagelist"] = 0;
				}

				//本地
				if($rs["uploadImages"])
				{
					$nimageslist = explode("|",$rs["uploadImages"]);
					$newimages="";
					foreach($nimageslist as $keys=>$rss)
					{
						$newimages[] =str_replace($url.":66","",$rss);
					}
					$list[$key]["uploadImages"] = $newimages;
				}
			}

			$this->tpl->assign("list", $list);
			$this->tpl->assign("urlID", $id);
			$this->tpl->display("magento/shopifyaddproductimages.tpl");
		}

				if($op =="shopifyshowImages")
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$id = $this->input->post('id');
			$list = $this->fun->getdatabasesdetail("shopify.db_shopify_productlist"," AND id='".$id."'");
			$imageslist = $list["uploadImages"];
			if($imageslist)
			{
				$imageslist = explode("|",$imageslist);
				foreach($imageslist as $key=>$rs)
				{
					$newimages[] =str_replace($url.":66","",$rs);
				}
				echo json_encode($newimages);
				die;
			}

			
		
		}

				if($op =="shopifysaveProductImages")
		{
			$url = $this->config->item('system_oray_url');
			$url = trim($url,"/");
			$ID = $this->input->post('MergeProductID');
			$insertID = $this->input->post('urlID');
			$filepath = $this->input->post('filepath');
			if(count($filepath))
			{
				foreach($filepath as $k=>$res)
				{
					$imageslist[]= $url.":66".$res;
				}
				$newimages = implode("|",$imageslist);
				$this->db->update("shopify.db_shopify_productlist",array("uploadImages"=>$newimages,"images_type"=>2),"id='".$ID."'");
			}
			$this->fun->phpalert(1, "上传完成", "/magento/ajaxbutton?op=shopifyaddproductimages&id={$insertID}");
			die;
		}

				if($op =='updateshopifywebdata')
		{
			$this->load->library('Shopifydata');
			$this->shopifydata->updateshopifywebdata();
			echo "等待更新中！";
			die;
		}

    }

    // function mb_unserialize($serial_str) {
    // $serial_str= preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
    // $serial_str= str_replace("\r", "", $serial_str);      
    // return unserialize($serial_str);
    // }


    //shopify 产品更新
    	public function shopifyproductlist()
	{
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
        $where = " ";
		
		
		
		if($this->input->get_post('webname'))
		{
			$webname = $this->input->get_post('webname');
			 $where.=" AND webname ='".$webname."'";
			 $this->tpl->assign("webnamevalue", $this->input->get_post('webname'));
		}


		$starttime = trim($this->input->get('starttime'));
		if ($starttime) {
			$times = $starttime . " 00:00:00";
			$timess = strtotime($times);
			$where .= " AND (intime >= '" . $timess . "')";
			$this->tpl->assign("starttime", $starttime);
		}

		$endtime = trim($this->input->get('endtime'));
		if ($endtime) {
			$times = $endtime . " 23:59:59";
			$endtimes = strtotime($times);
			$where .= " AND (intime <= '" . $endtimes. "')";
			$this->tpl->assign("endtime", $endtime);
		}
		if ($this->input->get_post('kw')) {
			$kw = trim($this->input->get_post('kw'));
			$where .= " AND (sku like '%" . $kw. "%' or name like '%" . $kw. "%')";
			$this->tpl->assign("kw", $kw);
		}

		$list = $this->fun->getalllist("shopify.db_shopify_productlist ", $where, $nowpage, $if_csv, 100, $orderby);
		foreach($list["list"] as $key=>$rs)
		{
			 $list["list"][$key]['name'] = stripslashes($rs['name']);
			 $list["list"][$key]['waittime'] =date("Y-m-d H:i:s",$rs['intime']);
			
		}

		$webname = $this->fun->getdatabaseslist("shopify.db_shopify_productlist","","DISTINCT webname ");
		$this->tpl->assign("webname", $webname);
		$pageList = $this->pagenav->page($list["total"], $nowpage,100);
        $this->tpl->assign("totalpage", ceil($list["total"] / 100));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
        $this->tpl->assign("productlist", $list["list"]);

		
		$this->tpl->display("magento/shopifyproductlist.tpl");
	}

		public function shopifyaddnewproduct()
	{
		$shopname = $this->db->get_where("d_shop"," (platfrom = 23  ) AND del_flag = 0 and id !=72 ")->result_array();
		$newshop = "";
		foreach($shopname as $key=>$rs)
		{
			$newshop[$rs["platfromname"]][] = $rs;
		}

		
		$this->tpl->assign("shopname", $newshop);
		$this->tpl->display("magento/shopifystorere.tpl");
	}
    
    	public function shopifysaveproductNext()
	{
		$goods_name = $this->input->post('goods_name');
		$sku = $this->input->post('sku');
		$category = $this->input->post('categorydata');//分类
		$categoryID = $this->input->post('categorydataID');//分类ID
		$price = $this->input->post('price');//价格
		$special_price = $this->input->post('special_price');//折扣价
		$weight = $this->input->post('weight');
		//$including = $this->input->post('includingdata');
		//$includingid = $this->input->post('includingdataid');
		//$fabric = $this->input->post('fabricdata');
		//$fabricid = $this->input->post('fabricdataid');
		$short_description = $this->input->post('short_description');
		$meta_title = $this->input->post('meta_title');
		$meta_keywords = $this->input->post('meta_keywords');
		$description = $this->input->post('description');
		$webname = $this->input->post('webname');
		$attributeID = $this->input->post('attributedata');
		$shopid = $this->input->post('shopid');
		// $related = $this->input->post('related');
		// $up_sell = $this->input->post('up_sell');
		
		$goodsid = $this->input->post('goodsid');

		if($goods_name)
		{
			$insertID="";
			foreach($goods_name as $key=>$rs)
			{
				$post="";
				$post["product_id"] = 0;
				$post["parent_id"] = 0;
				$post["webname"] = $webname[$key];
				$post["shopid"] = $shopid[$key];
				$post["is_open"] = 0;
				$post["sku"] = trim($sku);
				$post["name"] = $rs;
				$post["description"] = $description[$key];
				$post["short_description"] = $short_description[$key];
				$post["weight"] = $weight[$key];
				$post["categoryID"] = $categoryID[$key];
				$post["price"] = $price[$key];
				$post["special_price"] = $special_price[$key];
				$post["meta_title"] = $meta_title[$key];
				$post["meta_keywords"] = $meta_keywords[$key];
				// $post["including"] = $including[$key];
				// $post["fabric"] = $fabric[$key];
				$post["isupload"] = 0;
				// $post["includingid"] = $includingid[$key];
				// $post["fabricid"] = $fabricid[$key];
				$post["attributeid"] = $attributeID[$key];
                // $post['related'] = $related[$key];
                // $post['up_sell'] = $up_sell[$key];
                var_dump($post);
				if($goodsid){
					$this->db->update("shopify.db_shopify_productlist",$post,"id='".$goodsid."'");
					$insertID[] = $goodsid;
				}else{
					$this->db->insert("shopify.db_shopify_productlist",$post);
					$insertID[] = $this->db->insert_id();
				}
			}
		}

		
		if(count($insertID))
		{
			$insertID  = implode(",",$insertID);
			 header("location:/magento/ajaxbutton?op=shopifyaddproductimages&id={$insertID}");
		}else{
			die('没有数据');
		}
	}


		public function shopifysaveupload()
	{
		$url = $this->config->item('system_oray_url');
		$url = trim($url,"/");
		$imagetype = $this->input->post('imagetype');
		$id = $this->input->post('id');
		foreach($imagetype as $key=>$val)
		{
			$rsdb = $this->fun->getdatabasesdetail("shopify.db_shopify_productlist"," AND id ='".$id[$key]."'");
			if($val==1)
			{
				//系统用图片保存在待处理阶段
				$images = $this->fun->getdatabasesdetail("goodimages.goods"," AND number = '".$rsdb['sku']."'");
				$imagesID = $images["id"];
				$imageslist = $this->fun->getdatabaseslist("goodimages.goodpics"," AND type = 5 and pid = '".$imagesID."'","picurl");
				$imagesdata = "";
				if(count($imageslist)){
					
					foreach($imageslist as $k=>$res)
					{
						$imagesdata[]= $url.":50/".$res["picurl"];
					}
				}
				if($imagesdata)
				{
					$imagesdata = implode("|",$imagesdata);
					$this->db->update("shopify.db_shopify_productlist",array("uploadImages"=>$imagesdata,"images_type"=>1),"id='".$id[$key]."'");
				}
			}
		}
		//开始存储信息
		foreach($id as $key=>$val)
		{
			$rsdb = $this->fun->getdatabasesdetail("shopify.db_shopify_productlist"," AND id ='".$val."'");
			$Newarray  = array();
			$Newarray["name"] =  $rsdb["name"];
			$Newarray["weight"] =  $rsdb["weight"];
			$Newarray["price"] =  $rsdb["price"];
			$Newarray["special_price"] =  $rsdb["special_price"];
			$Newarray["short_description"] =  $rsdb["short_description"];
			$Newarray["including"] =  $rsdb["includingid"];
			$Newarray["attributeid"] =  $rsdb["attributeid"];
			$Newarray["fabric"] =  $rsdb["fabricid"];
			$Newarray["description"] =  $rsdb["description"];
			$Newarray["categoryID"] =  $rsdb["categoryID"];
			$Newarray['meta_keywords'] = $rsdb['meta_keywords'];
			$Newarray['meta_title'] = $rsdb['meta_title'];
			$Newarray["is_open"] =  0;
			$Newarray['related'] = $rsdb['related'];
			$Newarray['up_sell'] = $rsdb['up_sell'];
			$update =  json_encode($Newarray);
			$post="";
			$post["isupload"] = 1;
			$post["updateData"] = $update;
			$this->db->update('shopify.db_shopify_productlist',$post,"id=".$rsdb['id']);
		}

		 header("location:/magento/shopifyproductlist");
		 die;
		//开始直接更新数据
		$this->load->library('Magentodata');
		$this->magentodata->updatemagentwebdata();
		 header("location:/magento/shopifyproductlist");
		 die;
	}

}


?>